package org.edu.modules.jxzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.edu.modules.jxzy.entity.JwJiaocaiSupplier;
import org.edu.modules.jxzy.entity.JwJiaoshi;
import org.edu.modules.jxzy.mapper.JwJianzhuMapper;
import org.edu.modules.jxzy.mapper.JwJiaoshiMapper;
import org.edu.modules.jxzy.service.IJwJiaoshiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: 教室信息表
 * @Author: jeecg-boot
 * @Date:   2021-04-15
 * @Version: V1.0
 */
@Service
public class JwJiaoshiServiceImpl extends ServiceImpl<JwJiaoshiMapper, JwJiaoshi> implements IJwJiaoshiService {

    @Autowired
    private JwJianzhuMapper jianzhuMapper;

    @Override
    public void updateStatusByIds(String ids, int status) {
        List<String> list = Arrays.asList(ids.split(","));
        for (String str:list) {
            baseMapper.updateById(new JwJiaoshi().setId(Integer.parseInt(str)).setStatus(status));
        }
    }

    @Override
    public int queryCountByXqId(Integer xqId) {
        LambdaQueryWrapper<JwJiaoshi> wrapper =  new LambdaQueryWrapper<>();
        wrapper.eq(JwJiaoshi::getCampusid, xqId);
        wrapper.eq(JwJiaoshi::getIsdelete, 0);
        return this.count(wrapper);
    }

    @Override
    public int queryCountByJslx(Integer xqId, String jslx) {
        LambdaQueryWrapper<JwJiaoshi> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(JwJiaoshi::getJslxdm, jslx);
        wrapper.eq(JwJiaoshi::getCampusid, xqId);
        wrapper.eq(JwJiaoshi::getIsdelete, 0);
        return this.count(wrapper);
    }

    @Override
    public String queryNameById(Integer id) {
        JwJiaoshi js = getBaseMapper().selectById(id);
        if(js == null){
            return "";
        }
        return jianzhuMapper.selectNameById(js.getJzid()) + "-" + js.getJsmc();
    }
}
